package projectx.core.base;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.apache.log4j.xml.DOMConfigurator;

public final class ProjectXLog {

    private static final Logger _log = Logger.getLogger( ProjectXLog.class.getName() );

    private static boolean  _initialized;
    private static String   _fileName;


    public static void initialize( String fileName ) throws ProjectXSystemException {

        if ( !_initialized ){

            synchronized( ProjectXLog.class ){

                if ( !_initialized ){

                    _fileName = fileName;

                    PropertyConfigurator.configure( ResourceUtil.getResource( _fileName ) );
                    if (_fileName.endsWith(".xml")) {
            			DOMConfigurator.configure(ResourceUtil.getResource( _fileName ) );//Loader.getResource(_fileName));
            		} else {
            			PropertyConfigurator.configure(ResourceUtil.getResource( _fileName ) );//Loader.getResource(_fileName));
            		}

                    _log.info( "Initialized successfully using[" + _fileName + "]" );

                    _initialized = true;
                }
            }
        }
    }    

    public static boolean isInitialized(){ return _initialized; }

    public static void shutdown(){

        LogManager.shutdown();
    }

    private ProjectXLog(){}
}
